package com.bsh.serviceImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.bsh.dto.FeedbackQryDto;
import com.bsh.mybatis.model.Feedback;
import com.bsh.repository.DaoFeedback;
import com.bsh.service.FeedbackService;
import com.bsh.utils.Pager;

/**
 * 后台变动账户审核
 * 
 * @author gsh
 *
 */
@Service
@Transactional
public class FeedbackServiceImpl implements FeedbackService {
	@Autowired
	private DaoFeedback fbDao;

	@Override
	public List<Map<String, Object>> getPage(Pager pager, FeedbackQryDto qryParam) {
		StringBuilder where = new StringBuilder();
		where.append(" and stype =0 ");
		where.append(" or stype is null ");
		if (qryParam != null) {		
			if (!StringUtils.isEmpty(qryParam.getFeedback())) {
				where.append(String.format(" and feedback like '%%%s%%' ", qryParam.getFeedback().trim()));
			}			
		}

		List<Map<String, Object>> list = fbDao.getPage(pager, where.toString());
		return list;
	}

	/**
	 * 读取
	 */
	@Override
	public Feedback getMessage(Integer id) {
		return fbDao.selectByPrimaryKey(id);
	}

	/**
	 * 处理留言
	 */
	@Override
	public Integer process(Integer id, String msg) {
		Feedback fb = fbDao.selectByPrimaryKey(id);
		if(fb==null)return 0;
		fb.setAuditMsg(msg);
		fb.setStatus("1");
		return fbDao.updateByPrimaryKey(fb);
	}

	/**
	 * 移除
	 */
	@Override
	public Integer remove(int id) {
		return fbDao.deleteByPrimaryKey(id);
	}

	@Override
	public List<Map<String, Object>> getServiceRecords(Pager pager, FeedbackQryDto qryParam) {
		StringBuilder where = new StringBuilder();
		where.append(" and stype =1 ");
		if (qryParam != null) {		
			if (!StringUtils.isEmpty(qryParam.getMobile())) {
				where.append(String.format(" and mobile ='%s' ", qryParam.getMobile().trim()));
			}
		}

		List<Map<String, Object>> list = fbDao.getServiceRecordPage(pager, where.toString());
		return list;
	}

	@Override
	public Integer addFeedBack(Feedback feedback) {
		
		return fbDao.insert(feedback);
	}

}
